import asyncio
from mcp import ClientSession, types
from mcp.client.streamable_http import streamablehttp_client


async def main() -> None:
    server_url = "http://127.0.0.1:8000/mcp"
    async with streamablehttp_client(server_url) as (read_stream, write_stream, _):
        async with ClientSession(read_stream, write_stream) as session:
            await session.initialize()
            tools = await session.list_tools()
            print("[Tools]", [t.name for t in tools.tools])

            result = await session.call_tool("greet", {"name": "Alice"})
            texts = []
            for block in result.content:
                if isinstance(block, types.TextContent):
                    texts.append(block.text)
            print("[Call Greet]", "|".join(texts))


if __name__ == "__main__":
    asyncio.run(main())
